package com.hsl.study.listener;

import dev.langchain4j.model.chat.listener.ChatModelErrorContext;
import dev.langchain4j.model.chat.listener.ChatModelListener;
import dev.langchain4j.model.chat.listener.ChatModelRequestContext;
import dev.langchain4j.model.chat.listener.ChatModelResponseContext;
import lombok.extern.slf4j.Slf4j;

import java.util.UUID;

/**
 * @Author: hsl
 * @CreateTime: 2025-03-12  18:39
 */
@Slf4j
public class TestChatModelListener implements ChatModelListener {

    @Override
    public void onRequest(ChatModelRequestContext requestContext) {
        // onRequest配置的Map的K V键值对会传递到onResponse   上下方法中传递参数好用
        String string = UUID.randomUUID().toString().replaceAll("-","");
        requestContext.attributes().put("uuid",string);
        log.info("onRequest:{}",string);
    }

    @Override
    public void onResponse(ChatModelResponseContext responseContext) {
        Object object = responseContext.attributes().get("uuid");
        log.info("onResponse:{}",object);
    }

    @Override
    public void onError(ChatModelErrorContext errorContext) {
        ChatModelListener.super.onError(errorContext);
    }
}
